package se.webbzon.boltzmann.menu;

import java.awt.image.ImageObserver;

import se.webbzon.oschi01.font.VerticalAlignment;
import se.webbzon.oschi01.worldcamera.WorldCameraPane;

public class MLabel extends MItem {
	
	// The observer of this label item
	private final ImageObserver observer;
	
	// The layout of this label item
	private final LabelLayout layout;
	
	// The text of this menu label
	private final MText text;
	
	// Whatever this label button is long or short
	private boolean isLong;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a short game menu label with the given layout and text. **/
	public MLabel(ImageObserver observer, LabelLayout layout, String text) {
		this(observer,layout,false,text);
	}
	
	public MLabel(ImageObserver observer, LabelLayout layout, boolean isLong, String text) {
		this.observer = observer;
		this.layout = layout;
		this.isLong = isLong;
		this.text = new MText(layout,text);
		this.text.setVAlignment(VerticalAlignment.MIDDLE);
		this.text.setShadow(true);
		setWidth(layout.getLabelImage(isLong).get(0).getWidth(observer));
		setHeight(layout.getLabelImage(isLong).get(0).getHeight(observer));
	}
	
	/*============================================================
	Constructors
	============================================================*/

	/** Returns the text of this game menu label. **/
	public String getText() {
		return text.getText();
	}
	
	/** Sets the text of this game menu label. **/
	public void setText(String text) {
		this.text.setText(text);
	}
	
	/** Returns true if this game menu label is long. **/
	public boolean isLong() {
		return isLong;
	}
	
	/** Sets whatever this game menu label is long. **/
	public void setLong(boolean isLong) {
		if (this.isLong != isLong) {
			this.isLong = isLong;
			setWidth(layout.getLabelImage(isLong).get(0).getWidth(observer));
			setHeight(layout.getLabelImage(isLong).get(0).getHeight(observer));
		}
	}
	
	@Override public void onDraw(GameMenu menu, WorldCameraPane hud) {
		hud.drawImage(layout.getLabelImage(isLong).get(0), getX(), getY());
		hud.setFont(layout.getFont());
		hud.setColor(layout.getColor());
		text.draw(hud, getX() + layout.getTextX(), getY() + layout.getTextY());
	}

	@Override public void onPress(GameMenu menu, int x, int y) {};

	@Override public void onRelease(GameMenu menu, int x, int y) {};

	@Override public boolean isDraggable() {
		return false;
	}

	@Override public boolean isFocusable() {
		return false;
	}

}
